//
//  ModalitaInterventoViewController.m
//  InterventixApp
//
//  Created by Diego Falcinelli on 30/05/13.
//
//

#import "ModalitaInterventoViewController.h"
#import "Util.h"

@interface ModalitaInterventoViewController ()

@end

@implementation ModalitaInterventoViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.array = [NSMutableArray arrayWithCapacity:0];
    [self.array addObject:@"Contrattualizzato"];
    [self.array addObject:@"Pagamento Diretto"];
    [self.array addObject:@"Post-Vendita (Garanzia)"];
    [self.array addObject:@"Comodato d'uso"];
    
    [self.table reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction) indietro{
	[[self navigationController] popViewControllerAnimated:YES];
}



// TABELLA
#pragma mark - Tabella

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.array count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    if([self.intervento.idintervento intValue]<0)return @"Modalità Nuovo Intervento";
	return [NSString stringWithFormat: @"Modalità Intervento %@",self.intervento.idintervento];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    [cell setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1]];
    
    NSString *name = [self.array objectAtIndex:indexPath.row];
    
    cell.textLabel.text = name;
    if([self.intervento.modalita isEqualToString:[Util ModalitaInterventoToCode:name]]){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}


// CellHeight
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	return 50;
}

// CLICK
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *name = [self.array objectAtIndex:indexPath.row];
    self.nameSelect = name;
    self.intervento.modalita = [Util ModalitaInterventoToCode:name];
    [self.table reloadData];
}


@end
